import xlrd
from math import modf
import os

filepath = "C:\\Users\\Administrator\\Desktop\\地图数据\\地图基本数据.xls"
ExportPath = os.path.dirname(filepath)

xl = xlrd.open_workbook_xls(filepath)
sheet = xl.sheet_by_index(1)

attack_type = {}

# 提取数据(伤害_种族_系数)
# for index1 in range(1,12):
#     stirps = sheet.cell_value(0,index1)
#     attack_type[stirps] = {}
#     for index2 in range(1,11):
#         attack = sheet.cell_value(index2,0)
#         attack_type[stirps][attack] = sheet.cell_value(index2,index1)

# 提取数据(伤害_护甲_系数)
for index1 in range(14,21):
    stirps = sheet.cell_value(0,index1)
    attack_type[stirps] = {}
    for index2 in range(1,11):
        attack = sheet.cell_value(index2,0)
        attack_type[stirps][attack] = sheet.cell_value(index2,index1)

# 转换为书写格式
_str = ''
for stirps in attack_type:
    _str += "['%s'] = {\n" % (stirps)
    for attack in attack_type[stirps]:
        value = attack_type[stirps][attack]
        if modf(value)[0] == 0:
            _str += "\t['%s'] = %d;\n" % (attack,value)
        else:
            _str += "\t['%s'] = %s;\n" % (attack,str(value))
        
    _str += "};\n"

# sheet = xl.sheet_by_index(2)
# item_affixs = []
# unit_affixs = []
# for y in [0,5]:
#     for x in range(0,55):
#         if sheet.cell_value(x,5) :
#             _value = sheet.cell_value(x,y)
#             if _value != "" and y == 0:
#                 item_affixs.append(_value)
#             elif _value != "" and y == 5:
#                 unit_affixs.append(_value)

# # 转换为书写格式
# _str = ''
# for index in range(len(item_affixs)) :
#     _str += "hero:add('%s',- state.%s)\n" % (unit_affixs[index],item_affixs[index])
#     # _str += "{%s = 5000};\n" % (item_affixs[index])


# 打印
with open(ExportPath + '\\打印数据.txt','w') as fi:
    fi.write(_str)

